<?php
/*
 * Created on 05.01.2006
 *
 */

/**
 * Creates a hidden field with the doc id for applications working in editor view
 * attributes:
 * dataset
 * field
 */
class cms_loadimageHandler
{

    var $value;
    var $optiontext;
    var $selected;

    function startElement (& $sender, $attrs)
    {
        if (!$attrs['var'])
        {
            die ("cms:loadimage must have attribute var");
        }
        if (!$attrs['field'])
        {
            die ("cms:loadimage must have attribute field");
        }
        if (!$attrs['dataset'])
        {
            die ("cms:loadimage must have attribute dataset");
        }
        if (!$attrs['attributes'])
        {
            $attrs['attributes'] = "''";
        }
        if ($attrs['var'])
        {
            $var = substr($attrs['var'], 1, strlen($attrs['var'])-2);
            if (!preg_match('/\w+/', $var))
                die ("Attribute var must not contain EL code\n");
            $attrs['var'] = $var;
        }
        preg_match('/^(.*)href/',$attrs['field'],$matches);
        $name = $matches[1];
        $sender->appendCode('$__imgdataset = '.$attrs['dataset'].';preg_match(\'/^imageid:(\d+)$/\',$__imgdataset'.
                '['.$attrs['field'].'],$matches);$'.$attrs['var'].' = $GLOBALS[\'dba\']->getImage($matches[1]);'."\n");
    }
    
    function endElement (& $sender)
    {
    }

} 

?>